<?php

/**
 * Article form.
 *
 * @package    myarticles
 * @subpackage form
 * @author     Apul Gupta<apulmca2k4@gmail.com>
 */
class ArticleForm extends BaseArticleForm
{
    
  public function configure()
  {
     

      if($this->getOption("isFront"))
      {
        $this->useFields(array('title', 'meta_keyword', 'meta_description',
                             'content', 'author_speech', 'article_summary',
                             'article_source', 'article_category_list'));
      }
      else
      {
       $this->useFields(array('title', 'meta_keyword', 'meta_description',
                             'content', 'author_speech', 'article_summary',
                             'article_source', 'article_category_list', 'is_active'));
      }
      
      $this->widgetSchema['article_summary'] = new sfWidgetFormTextarea();
      $this->widgetSchema['author_speech']   = new sfWidgetFormTextarea();
      $this->widgetSchema['content']         = new sfWidgetFormTextareaTinyMCE(
                                                   array( 'width'  => 380,
                                                          'height' => 200,
                                                          'theme'  => 'advanced',
                                                          'config' => 'theme_advanced_disable: "anchor,image,cleanup,help,html",
                                                                       forced_root_block:""'
                                                     ));
      $this->widgetSchema['article_category_list'] = new sfWidgetFormPropelChoice(
                                                         array('multiple' => false, 'model' => 'Category', 'peer_method' => 'doSelectForArticle', 'add_empty' => false),
                                                         array('style' => 'padding-left: 5px')
                                                     );

      $this->widgetSchema['meta_description']   = new sfWidgetFormTextarea();
      $this->widgetSchema['meta_keyword']       = new sfWidgetFormTextarea();
      
      $this->validatorSchema['title']          =  new sfValidatorAnd(array($this->validatorSchema['title']));
      $this->validatorSchema['article_category_list']->setOption('required', true);
      
      $this->validatorSchema['content']        =  new sfValidatorAnd(array($this->validatorSchema['content'], /*new sfValidatorString(array('min_length' => 200)), */ new sfSpamValidator()));
      $this->validatorSchema['article_source'] =  new sfValidatorAnd(array($this->validatorSchema['article_source'], new sfValidatorUrl()));
      $this->validatorSchema['article_source']->setOption('required', false);
        
      $this->validatorSchema->setPostValidator(new sfValidatorPropelUnique(array('model'=> 'Article', 'column' => array('title')), array('invalid'=>'Title Exist!')));
     // $this->validatorSchema->setPostValidator(new sfValidatorPropelUnique(array('model'=> 'Article', 'column' => array('content')), array('invalid'=>'Duplicate Article Content!')));
      
   }

     public function setValue($key, $value)
     {
         $this->values[$key] = $value;
     }
}
